<template>
  <div>
    <van-nav-bar title="追加物料" left-text="返回" left-arrow @click-left="onClickLeft" />
    <el-main v-model="ewmMsg">
      <div style="margin-top: 20px;">
        <div class="addone">
          <div class="addone_1">
            <div class="font">物料条码：</div>
            <!-- <textarea type="text" ref="gcdInputVal" class="tatile_style" @keyup.enter.native="addinvCode"
              v-model="gdbh">{{ gdbh }}</textarea> -->
            <el-input v-model="gdbh" ref="gcdInputVal" class="tatile_style" @keyup.enter.native="addinvCode">{{ gdbh
            }}</el-input>
          </div>
          <div class="addone_1">
            <div class="font">批次号：</div>
            <el-input type="text" ref="" class="tatile_style" readonly="true" v-model="ProBat">{{ ProBat }}</el-input>
          </div>
        </div>
        <div class="addone" style="margin-top: 20px;">
          <div class="addone_1">
            <div class="font">工序：</div>
            <el-input type="text" ref="" class="tatile_style" v-model="RonNo">{{ RonNo }}</el-input>
          </div>
          <div class="addone_1">
            <div class="font">数量：</div>
            <el-input type="text" ref="" class="tatile_style" v-model="Qty">{{ Qty }}</el-input>
          </div>
        </div>
        <!-- <div class="addone2"  style="margin-top: 20px;">
        <div class="addone_2" >
          <div class="font">下限：</div>
          <textarea type="text" ref="gcdInputVal" class="tatile_style" @keypress="codeWhow" v-model="gdbh"
            @focus="upco($event)" @blur="upco($event)"></textarea>
        </div>
      </div> -->
        <div class="addone" style="margin-top: 20px;">
          <div class="addone_1">
            <div class="font">上限：</div>
            <el-input type="text" ref="" class="tatile_style" v-model="topLimit">{{ topLimit }}</el-input>
          </div>
          <div class="addone_1">
            <div class="font">下限：</div>
            <el-input type="text" ref="" class="tatile_style" v-model="lowerLimit">{{ lowerLimit }}</el-input>
          </div>
        </div>
      </div>
    </el-main>
    <div class="example-body">
      <van-button class="tbutt" size="large" color="steelblue" @click="conf">确认</van-button>
      <van-button class="tbutt" size="large" color="steelblue" @click="onClickLeft">取消</van-button>
    </div>
  </div>
</template>

<script>
import { ref, onMounted, onUnmounted } from "vue";
import router from "@/router";
import { Toast, Dialog } from "vant";
export default {
  name: "addInv",
  setup() {
    const gdbh = ref(""); //物料条码
    const ProBat = ref("") //批次号
    const RonNo = ref("") //工序
    const Qty = ref("") //数量
    const topLimit = ref("") //上限
    const lowerLimit = ref("") //下限
    const ewmMsg = ref({});
    const codeWhow = (e) => {
      if (e.keyCode == 13) {
        if (!gdbh.value) {
          console.log("ddd", e)
        }
      }
    }
    const addinvCode = e => {
      debugger;
      console.log(e);
      if (e.keyCode == 13) {
        console.log(gdbh.value);
        console.log(gdbh.value.split("-")[0]);
        console.log(ewmMsg.value.fG_InvChild);
        ewmMsg.value.fG_InvChild.forEach(element => {
          if (!gdbh.value) {
            Toast.fail("物料条码不能为空！");
            gdbh.value.focus();
            return;
          } else if (gdbh.value == element.inventoryID) {
            Toast.fail("该物料在工单中存在！");
            gdbh.value = "";
            ProBat.value = "";
            return;
          } else {
            ProBat.value = e.target.value.split("-")[1];
            gdbh.value = e.target.value.split("-")[0]
          }
        });

      }
    }
    const conf = e => {
      if (gdbh.value == "" || ProBat.value == "" || RonNo.value == "" || Qty.value == "" || UpQty.value == "" || DownQty.value == "") {
        Toast.fail("数据不能为空！");
      } else {
        console.log(ewmMsg.value)
        let obj = {};
        obj.pid = ewmMsg.value.id;
        obj.rountNo = RonNo.value;
        obj.inventoryID = gdbh.value;
        obj.planQty = Qty.value;
        obj.tolerance=0;
        obj.topLimit = topLimit.value;
        obj.lowerLimit = lowerLimit.value;
        obj.projectBatch = ProBat.value;
        obj.scale = "A";
        obj.combination = "A";
        obj.status = 1;
        console.log(obj);
        DotNet.invokeMethodAsync("Rmac", "InsertIssueChild", JSON.stringify(obj)).then(res => {
          console.log(res);
          ewmMsg.value.fG_InvChild.push(res)
          router.push({
            name: "DZCL",
            params: { data:res }
          });
        });

      }
    }

    const conce = e => { }
    const upco = (event) => {
      switch (event.type) {
        case "focus":
          event.target.style.backgroundColor = 'white'
          break
        case "blur":
          event.target.style.backgroundColor = "#eeeeee"
          break
        default:
          break
      }
    }
    const onClickLeft = () => {
      router.push({
            name: "Feeding",
            params: { data:ewmMsg.value.fG_InvChild[0] }
          });
    };
    onMounted(function () {
      // console.log(router.currentRoute.params.data);
      ewmMsg.value = router.currentRoute.params.data;
      console.log(ewmMsg)
    })
    return {
      gdbh,
      ProBat,
      RonNo,
      Qty,
      topLimit,
      lowerLimit,
      codeWhow,
      upco,
      onClickLeft,
      ewmMsg,
      addinvCode,
      conf,
      conce
    }
  }
}
</script>
<style>
.FHimg {
  text-align: left;
  padding: 10px 0 0 10px;

}

.font {
  text-align: lert;
  font-size: 30px;
  /* font-family: "Lucida Calligraphy", cursive, serif, sans-serif; */
  font-weight: bold;
  color: white;
  padding-left: 10px;
  height: 50px;
  padding-top: 20px;
  width: 29%;
}

.tatile_style {
  background-color: #EEEEEE;
  resize: none;
  width: 300px;
  height: 50px;
  margin-left: 10px;
  margin-top: 20px;
  line-height: 50px;
  font-size: 30px;
  border: none
}

.example-body {
  display: flex;
  justify-content: space-evenly;
  bottom: 0;
  clear: both;
  margin-top: 20px;
  width: 100%;
  vertical-align: bottom;
  position: absolute;
  bottom: 50px
}

.tbutt {
  margin-right: 5px;
  border-radius: 15px;
  font-size: 20px;
  width: 15%;
  box-shadow: 0px 5px 19px 0px darkblue;

}

.addone {
  display: flex;
  justify-content: space-around;
}

.addone_1 {
  display: flex;
  width: 50%;
}
</style>